package com.wdh.kjs.activity;

import android.graphics.Bitmap;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wdh.kjs.R;
import com.wdh.kjs.manager.ImageLoadManager;

/**
 * Created by codingWw on 2016/3/8.
 */
public class BaseTopActivity extends FragmentActivity {

    protected LinearLayout ll_topBack;
    protected TextView tv_topTitle;

    protected void initTopBar(String title) {
        ll_topBack = (LinearLayout) findViewById(R.id.ll_topBack);
        tv_topTitle = (TextView) findViewById(R.id.tv_topTitle);

        tv_topTitle.setText(title);
        ll_topBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    public void setText(int viewId, String text) {
        TextView tv = getView(viewId);
        tv.setText(text);
    }

    public void setText(int viewId, int textId) {
        TextView tv = getView(viewId);
        tv.setText(textId);
    }

    public void setImageResource(int viewId, int drawableId) {
        ImageView iv = getView(viewId);
        iv.setImageResource(drawableId);
    }

    public void setImageBitmap(int viewId, Bitmap bm) {
        ImageView iv = getView(viewId);
        iv.setImageBitmap(bm);
    }

    public void setImageByURL(int viewId, final String url) {
        ImageView iv = getView(viewId);
        ImageLoadManager.getInstance(this).displayImage(url, iv);
    }

    public <T extends View>T getView(int viewId) {
        View view  = findViewById(viewId);
        return (T)view;
    }
}
